package LeetCode;

/**
 * @author VX5
 * @Title: MJC
 * @ProjectName DataStructure
 * @Description: TODO
 * @date ${DAT}17:04
 */
public class interview42 {
    public static void main(String[] args) {
        int[] arr={-2,1,-3,4,-1,2,1,-5,4};
        System.out.println(new interview42().maxSubArray(arr));
    }
    public int maxSubArray(int[] nums){
        int result = nums[0];
        for (int i = 1; i < nums.length; i++){
            nums[i] += Math.max(nums[i-1],0);
            result = Math.max(result,nums[i]);
        }
        return result;
    }
//    public int maxSubArray(int[] nums) {
//        int result = nums[0];
//        for (int i = 1; i < nums.length;i++){
//            nums[i] += Math.max(nums[i-1],0);
//            result = Math.max(result,nums[i]);
//        }
//        return result;
//    }
}
